<% if @release %>
  <% case @release.releaseState %>
  <% when 'open' %>
    <% compiling = @environment.ciState == 'locked'
       deploying = @deployment && !%w(complete canceled).index(@deployment.deploymentState)
       comments = @environment.comments %>
    <div class="marker"><%= status_marker('release', 'open', state_to_label(@release.releaseState)) %></div>
    <div class="description">
      <ul class="status-items">
        <li><%= icon('star', ' ', 'fa-fw') %>Environment release <%= @release.releaseId %> created
          <strong><%= time_ago_in_words(@release.created_timestamp) %></strong></li>
        <li><%= icon('user', ' ', 'fa-fw') %>Created by <strong><%= @release.createdBy %></strong></li>
        <li>
          <% change_count = @release.rfc_cis.size + @release.rfc_relations.size %>
          <%= icon('th-list', ' ', 'fa-fw') %>Release
          contains <%= count_marker(change_count, 'badge-info') %> <%= 'change'.pluralize(change_count) %>
        </li>
        <% if @deployment && %w(active failed).index(@deployment.deploymentState) %>
          <li><%= icon('ban', ' ', 'fa-fw') %><%= highlight('Commit') %> is disabled due
            to <%= highlight(@deployment.deploymentState) %> deployment
          </li>
        <% end %>
        <% if @deployment && ['failed'].index(@deployment.deploymentState) %>
          <li><%= icon('ban', ' ', 'fa-fw') %>Please <strong>cancel</strong> the failed deployment in
            order to proceed
            with the commit
          </li>
        <% end %>
        <% if compiling %>
          <li><div class="alert alert-warning">You can not commit or discard while deployment preparation is in progress.</div></li>
        <% end %>
        <% error_prefix = 'ERROR:BOM:' %>
        <% if comments.present? && comments.start_with?(error_prefix) %>
          <li><%= content_tag(:div, raw(comments.sub(/^#{error_prefix}/, '').gsub("\n", '<br>')), :class => 'alert alert-danger') %></li>
        <% end %>
      </ul>
      <ul class="status-actions">
        <li>
          <%= link_to('Review',
                      assembly_transition_environment_path(@assembly, @environment, :anchor => path_to_release(@release).split('#').last),
                      :class => 'btn btn-primary') %>
        </li>
        <% if has_transition?(@assembly.ciId) %>
          <li>
            <% if compiling %>
              <%= button('Discard', nil, 'danger disabled') %>
            <% else %>
              <%= link_confirm_busy(button('Discard', nil, 'danger'),
                                    :url     => discard_assembly_transition_environment_path(@assembly, @environment),
                                    :method  => :post,
                                    :confirm => 'Discard environment changes?',
                                    :busy    => 'Discarding environment changes...') %>
            <% end %>
          </li>
          <li>
            <% if compiling %>
              <%= button('Commit', nil, 'success disabled') %>
            <% else %>
              <%= render 'transition/commit_and_deploy_prompt', :button_label => deploying ? 'Commit' : 'Commit & Deploy', :platforms => @platforms.map(&:toCi) %>
            <% end %>
          </li>
        <% end %>
      </ul>
    </div>
  <% else %>
    <% state = (@release.releaseState == 'closed') ? 'commit' : 'discard' %>
    <div class="marker"><%= status_marker('release', @release.releaseState, @release.releaseState == 'canceled' ? 'label-important' : '') %></div>
    <div class="description">
      <ul>
        <li><%= icon('arrow-circle-o-down', ' ', 'fa-fw') %>Last environment
          release <%= @release.releaseId %> <%= "#{state}" %>
          <strong><%= time_ago_in_words(@release.updated_timestamp) %></strong></li>
        <li><%= icon('user', ' ', 'fa-fw') %>Commit by <strong><%= @release.commitedBy %></strong></li>
        <% if @release.description.present? %>
          <li><%= icon('comment') %><%= @release.description %></li>
        <% end %>
        <li><%= icon('th-list', ' ', 'fa-fw') %><%= link_to(highlight('View', 'info'), '#timeline/timeline_list/filter::type=release') %>
          history of environment releases
        </li>
      </ul>
      <% if @platform_instance_counts.values.sum > 0 && has_transition?(@assembly.ciId) %>
        <ul class="status-actions">
          <li>
            <%= link_confirm_busy(button('Disable Environment', 'danger'),
                                  :url     => disable_assembly_transition_environment_path(@assembly, @environment, :platformCiIds => @platforms.map(&:toCiId)),
                                  :method  => :put,
                                  :remote  => true,
                                  :confirm => 'Disable environment...',
                                  :body    => raw('<p>This action will disable all platforms and generate a release that needs to be deployed in order to remove all cloud components related to this environment.</p>
                                                   <p>If you want to proceed select OK below and proceed with a "Commit & Deploy" action. If you change your mind you can "Discard" the release.</p>
                                                   <p>Note that disable action will not remove any configuration for this environment and you can enable the platforms at a later time.</p>
                                                   <p><strong class="label label-important">WARNING: No application data will be saved.</strong></p>')) %>
          </li>
        </ul>
      <% end %>
    </div>
  <% end %>
<% end %>
